import 'package:flutter/material.dart';
import 'package:macnov/common/alerts.dart';
import 'package:macnov/common/login_options.dart';
import 'package:macnov/common/passcode_screen.dart';
import 'package:macnov/common/profile.dart';
import 'package:macnov/common/requests.dart';
import 'package:macnov/common/send_funds.dart';
import 'package:macnov/role_employee/budget/budget_detail.dart' as employee;
import 'package:macnov/role_owner/budget/budget_detail.dart' as owner;
import 'package:macnov/role_owner/budget/budget_edit.dart' as owner;
import 'package:macnov/role_owner/budget/budget_add.dart' as owner;

import 'package:macnov/role_owner/budget/owner_select.dart' as owner;
import 'package:macnov/role_owner/budget/member_select.dart' as owner;


import 'package:macnov/role_owner/transaction/transaction_detail.dart';
import 'package:macnov/role_owner/wallet/vcarddetailsscene.dart';
import 'package:macnov/signin/signin.dart';

// owner
import 'package:macnov/role_owner/bottom_navigation_widget.dart' as owner;
import 'package:macnov/role_owner/budget/select_budget.dart' as owner;
import 'package:macnov/role_owner/wallet/addcard.dart' as owner;

// employee
import 'package:macnov/role_employee/bottom_navigation_widget.dart' as employee;
import 'package:macnov/role_employee/budget/select_budget.dart' as employee;
import 'package:macnov/role_employee/wallet/addcard.dart' as employee;
import 'dart:math' as math;
import 'dart:io';

void main() => runApp(MacnovApp());

class MacnovApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        child: MaterialApp(
      title: 'Macnov home',
      theme: Platform.isIOS
          ? ThemeData(brightness: Brightness.light, fontFamily: 'SFStyle')
          : ThemeData(brightness: Brightness.light),
      initialRoute: '/',
      routes: <String, WidgetBuilder>{
        '/': (BuildContext context) => Login(),
        '/owner': (BuildContext context) => owner.BottomNavigationWidget(),
        '/owner/newcard': (BuildContext context) => owner.AddCard(),
        '/owner/selectbudget': (BuildContext context) => owner.SelectBudget(),
        '/owner/budget_edit': (BuildContext context) => owner.BudgetEdit(),
        '/owner/budget_add': (BuildContext context) => owner.BudgetAdd(),
        
        '/employee': (BuildContext context) =>
            employee.BottomNavigationWidget(),
        '/employee/newcard': (BuildContext context) => employee.AddCard(),
        '/employee/selectbudget': (BuildContext context) =>
            employee.SelectBudget(),
        '/profile': (BuildContext context) => Profile(),
        '/sendfunds': (BuildContext context) => SendFunds(),
        '/requests': (BuildContext context) => Requests(),
        '/alerts': (BuildContext context) => Alerts(),
        '/loginOpt': (BuildContext context) => LoginOptions(),
        '/passcode': (BuildContext context) => PasscordScene(),
        '/employee/budget_detail': (BuildContext context) =>
            employee.BudgetDetail(),
        '/owner/budget_detail': (BuildContext context) => owner.BudgetDetail(),
        '/vCardDetails': (BuildContext context) => VirtualCardDetailsScene(),
        '/txndetail': (BuildContext context) => TransactionDetail(),
      },
      builder: (ctx, w) {
        return MaxScaleTextWidget(
          max: 1.0,
          child: w,
        );
      },
    ));
  }
}

class NoScaleTextWidget extends StatelessWidget {
  final Widget child;

  const NoScaleTextWidget({
    Key key,
    @required this.child,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaxScaleTextWidget(
      max: 1.0,
      child: child,
    );
  }
}

class MaxScaleTextWidget extends StatelessWidget {
  final double max;
  final Widget child;

  const MaxScaleTextWidget({
    Key key,
    this.max = 1.2,
    @required this.child,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var data = MediaQuery.of(context);
    var scale = math.min(max, data.textScaleFactor);
    return MediaQuery(
      data: data.copyWith(textScaleFactor: scale),
      child: child,
    );
  }
}
